<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: NavigationTest</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.npc.ghost</a> ]
    </div>

    <h1>Coverage Summary for Class: NavigationTest (nl.tudelft.jpacman.npc.ghost)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">NavigationTest</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 10)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 57)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.npc.ghost;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import com.google.common.collect.Lists;
        <i>4</i>&nbsp;import nl.tudelft.jpacman.board.Board;
        <i>5</i>&nbsp;import nl.tudelft.jpacman.board.BoardFactory;
        <i>6</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
        <i>7</i>&nbsp;import nl.tudelft.jpacman.board.Square;
        <i>8</i>&nbsp;import nl.tudelft.jpacman.board.Unit;
        <i>9</i>&nbsp;import nl.tudelft.jpacman.level.LevelFactory;
        <i>10</i>&nbsp;import nl.tudelft.jpacman.level.MapParser;
        <i>11</i>&nbsp;import nl.tudelft.jpacman.level.Pellet;
        <i>12</i>&nbsp;import nl.tudelft.jpacman.npc.Ghost;
        <i>13</i>&nbsp;import nl.tudelft.jpacman.points.PointCalculator;
        <i>14</i>&nbsp;import nl.tudelft.jpacman.sprite.PacManSprites;
        <i>15</i>&nbsp;import org.junit.jupiter.api.BeforeEach;
        <i>16</i>&nbsp;import org.junit.jupiter.api.Test;
        <i>17</i>&nbsp;
        <i>18</i>&nbsp;import java.io.IOException;
        <i>19</i>&nbsp;import java.io.InputStream;
        <i>20</i>&nbsp;import java.util.List;
        <i>21</i>&nbsp;
        <i>22</i>&nbsp;import static org.assertj.core.api.Assertions.assertThat;
        <i>23</i>&nbsp;import static org.mockito.Mockito.mock;
        <i>24</i>&nbsp;
        <i>25</i>&nbsp;/**
        <i>26</i>&nbsp; * Tests the various methods provided by the {@link Navigation} class.
        <i>27</i>&nbsp; *
        <i>28</i>&nbsp; * @author Jeroen Roosen
        <i>29</i>&nbsp; */
        <i>30</i>&nbsp;@SuppressWarnings({&quot;magicnumber&quot;, &quot;PMD.AvoidDuplicateLiterals&quot;})
        <b class="nc"><i>31</i>&nbsp;class NavigationTest {</b>
        <i>32</i>&nbsp;
        <i>33</i>&nbsp; /**
        <i>34</i>&nbsp; * Map parser used to construct boards.
        <i>35</i>&nbsp; */
        <i>36</i>&nbsp; private MapParser parser;
        <i>37</i>&nbsp;
        <i>38</i>&nbsp; /**
        <i>39</i>&nbsp; * Set up the map parser.
        <i>40</i>&nbsp; */
        <i>41</i>&nbsp; @BeforeEach
        <i>42</i>&nbsp; void setUp() {
        <b class="nc"><i>43</i>&nbsp; PacManSprites sprites = new PacManSprites();</b>
        <b class="nc"><i>44</i>&nbsp; LevelFactory levelFactory = new LevelFactory(</b>
        <i>45</i>&nbsp; sprites,
        <i>46</i>&nbsp; new GhostFactory(sprites),
        <b class="nc"><i>47</i>&nbsp; mock(PointCalculator.class));</b>
        <b class="nc"><i>48</i>&nbsp; parser = new MapParser(levelFactory, new BoardFactory(sprites));</b>
        <i>49</i>&nbsp; }
        <i>50</i>&nbsp;
        <i>51</i>&nbsp; /**
        <i>52</i>&nbsp; * Verifies that the path to the same square is empty.
        <i>53</i>&nbsp; */
        <i>54</i>&nbsp; @Test
        <i>55</i>&nbsp; void testShortestPathEmpty() {
        <b class="nc"><i>56</i>&nbsp; Board b = parser.parseMap(Lists.newArrayList(&quot; &quot;)).getBoard();</b>
        <b class="nc"><i>57</i>&nbsp; Square s1 = b.squareAt(0, 0);</b>
        <b class="nc"><i>58</i>&nbsp; Square s2 = b.squareAt(0, 0);</b>
        <b class="nc"><i>59</i>&nbsp; List&lt;Direction&gt; path = Navigation</b>
        <b class="nc"><i>60</i>&nbsp; .shortestPath(s1, s2, mock(Unit.class));</b>
        <b class="nc"><i>61</i>&nbsp; assertThat(path).isEmpty();</b>
        <i>62</i>&nbsp; }
        <i>63</i>&nbsp;
        <i>64</i>&nbsp; /**
        <i>65</i>&nbsp; * Verifies that if no path exists, the result is &lt;code&gt;null&lt;/code&gt;.
        <i>66</i>&nbsp; */
        <i>67</i>&nbsp; @Test
        <i>68</i>&nbsp; void testNoShortestPath() {
        <b class="nc"><i>69</i>&nbsp; Board b = parser</b>
        <b class="nc"><i>70</i>&nbsp; .parseMap(Lists.newArrayList(&quot;#####&quot;, &quot;# # #&quot;, &quot;#####&quot;))</b>
        <b class="nc"><i>71</i>&nbsp; .getBoard();</b>
        <b class="nc"><i>72</i>&nbsp; Square s1 = b.squareAt(1, 1);</b>
        <b class="nc"><i>73</i>&nbsp; Square s2 = b.squareAt(3, 1);</b>
        <b class="nc"><i>74</i>&nbsp; List&lt;Direction&gt; path = Navigation</b>
        <b class="nc"><i>75</i>&nbsp; .shortestPath(s1, s2, mock(Unit.class));</b>
        <b class="nc"><i>76</i>&nbsp; assertThat(path).isNull();</b>
        <i>77</i>&nbsp; }
        <i>78</i>&nbsp;
        <i>79</i>&nbsp; /**
        <i>80</i>&nbsp; * Verifies that having no traveller ignores terrain.
        <i>81</i>&nbsp; */
        <i>82</i>&nbsp; @Test
        <i>83</i>&nbsp; void testNoTraveller() {
        <b class="nc"><i>84</i>&nbsp; Board b = parser</b>
        <b class="nc"><i>85</i>&nbsp; .parseMap(Lists.newArrayList(&quot;#####&quot;, &quot;# # #&quot;, &quot;#####&quot;))</b>
        <b class="nc"><i>86</i>&nbsp; .getBoard();</b>
        <b class="nc"><i>87</i>&nbsp; Square s1 = b.squareAt(1, 1);</b>
        <b class="nc"><i>88</i>&nbsp; Square s2 = b.squareAt(3, 1);</b>
        <b class="nc"><i>89</i>&nbsp; List&lt;Direction&gt; path = Navigation.shortestPath(s1, s2, null);</b>
        <b class="nc"><i>90</i>&nbsp; assertThat(path).containsExactly(Direction.EAST, Direction.EAST);</b>
        <i>91</i>&nbsp; }
        <i>92</i>&nbsp;
        <i>93</i>&nbsp; /**
        <i>94</i>&nbsp; * Tests if the algorithm can find a path in a straight line.
        <i>95</i>&nbsp; */
        <i>96</i>&nbsp; @Test
        <i>97</i>&nbsp; void testSimplePath() {
        <b class="nc"><i>98</i>&nbsp; Board b = parser.parseMap(Lists.newArrayList(&quot;####&quot;, &quot;# #&quot;,
            &quot;####&quot;))</b>
        <b class="nc"><i>99</i>&nbsp; .getBoard();</b>
        <b class="nc"><i>100</i>&nbsp; Square s1 = b.squareAt(1, 1);</b>
        <b class="nc"><i>101</i>&nbsp; Square s2 = b.squareAt(2, 1);</b>
        <b class="nc"><i>102</i>&nbsp; List&lt;Direction&gt; path = Navigation</b>
        <b class="nc"><i>103</i>&nbsp; .shortestPath(s1, s2, mock(Unit.class));</b>
        <b class="nc"><i>104</i>&nbsp; assertThat(path).containsExactly(Direction.EAST);</b>
        <i>105</i>&nbsp; }
        <i>106</i>&nbsp;
        <i>107</i>&nbsp; /**
        <i>108</i>&nbsp; * Verifies that the algorithm can find a path when it has to take corners.
        <i>109</i>&nbsp; */
        <i>110</i>&nbsp; @Test
        <i>111</i>&nbsp; void testCornerPath() {
        <b class="nc"><i>112</i>&nbsp; Board b = parser.parseMap(</b>
        <b class="nc"><i>113</i>&nbsp; Lists.newArrayList(&quot;####&quot;, &quot;# #&quot;, &quot;## #&quot;, &quot;####&quot;)).getBoard();</b>
        <b class="nc"><i>114</i>&nbsp; Square s1 = b.squareAt(1, 1);</b>
        <b class="nc"><i>115</i>&nbsp; Square s2 = b.squareAt(2, 2);</b>
        <b class="nc"><i>116</i>&nbsp; List&lt;Direction&gt; path = Navigation</b>
        <b class="nc"><i>117</i>&nbsp; .shortestPath(s1, s2, mock(Unit.class));</b>
        <b class="nc"><i>118</i>&nbsp; assertThat(path).containsExactly(Direction.EAST, Direction.SOUTH);</b>
        <i>119</i>&nbsp; }
        <i>120</i>&nbsp;
        <i>121</i>&nbsp; /**
        <i>122</i>&nbsp; * Verifies that the nearest object is detected.
        <i>123</i>&nbsp; */
        <i>124</i>&nbsp; @Test
        <i>125</i>&nbsp; void testNearestUnit() {
        <b class="nc"><i>126</i>&nbsp; Board b = parser</b>
        <b class="nc"><i>127</i>&nbsp; .parseMap(Lists.newArrayList(&quot;#####&quot;, &quot;# ..#&quot;, &quot;#####&quot;))</b>
        <b class="nc"><i>128</i>&nbsp; .getBoard();</b>
        <b class="nc"><i>129</i>&nbsp; Square s1 = b.squareAt(1, 1);</b>
        <b class="nc"><i>130</i>&nbsp; Square s2 = b.squareAt(2, 1);</b>
        <b class="nc"><i>131</i>&nbsp; Square result = Navigation.findNearest(Pellet.class, s1).getSquare();</b>
        <b class="nc"><i>132</i>&nbsp; assertThat(result).isEqualTo(s2);</b>
        <i>133</i>&nbsp; }
        <i>134</i>&nbsp;
        <i>135</i>&nbsp; /**
        <i>136</i>&nbsp; * Verifies that there is no such location if there is no nearest object.
        <i>137</i>&nbsp; */
        <i>138</i>&nbsp; @Test
        <i>139</i>&nbsp; void testNoNearestUnit() {
        <b class="nc"><i>140</i>&nbsp; Board b = parser.parseMap(Lists.newArrayList(&quot; &quot;)).getBoard();</b>
        <b class="nc"><i>141</i>&nbsp; Square s1 = b.squareAt(0, 0);</b>
        <b class="nc"><i>142</i>&nbsp; Unit unit = Navigation.findNearest(Pellet.class, s1);</b>
        <b class="nc"><i>143</i>&nbsp; assertThat(unit).isNull();</b>
        <i>144</i>&nbsp; }
        <i>145</i>&nbsp;
        <i>146</i>&nbsp; /**
        <i>147</i>&nbsp; * Verifies that there is ghost on the default board
        <i>148</i>&nbsp; * next to cell [1, 1].
        <i>149</i>&nbsp; *
        <i>150</i>&nbsp; * @throws IOException if board reading fails.
        <i>151</i>&nbsp; */
        <i>152</i>&nbsp; @Test
        <i>153</i>&nbsp; void testFullSizedLevel() throws IOException {
        <b class="nc"><i>154</i>&nbsp; try (InputStream i = getClass().getResourceAsStream(&quot;/board.txt&quot;))
            {</b>
        <b class="nc"><i>155</i>&nbsp; Board b = parser.parseMap(i).getBoard();</b>
        <b class="nc"><i>156</i>&nbsp; Square s1 = b.squareAt(1, 1);</b>
        <b class="nc"><i>157</i>&nbsp; Unit unit = Navigation.findNearest(Ghost.class, s1);</b>
        <b class="nc"><i>158</i>&nbsp; assertThat(unit).isNotNull();</b>
        <b class="nc"><i>159</i>&nbsp; }</b>
        <i>160</i>&nbsp; }
        <i>161</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
